package com.naraba.socket.niosocket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @auther xjl
 * @date 2020/10/28
 * @description
 **/
public class UserInputHandler implements Runnable{

    ChatClient chatClient;

    public UserInputHandler(ChatClient chatClient) {
        this.chatClient = chatClient;
    }

    @Override
    public void run() {

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in)
        );
        while (true) {
            try {
                String input = reader.readLine();
                chatClient.send(input);
                if (input.equals("quit")) {
                    break;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }
}
